package com.example.zk2_lx.register;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ToastUtils;
import com.example.zk2_lx.R;
import com.example.zk2_lx.databinding.ActivityRegisterBinding;
import com.example.zk2_lx.mvvm_base.BaseActivity;

@Route(path = "/app/RegisterActivity")
public class RegisterActivity extends BaseActivity<ActivityRegisterBinding,RegisterViewMolde> {

    @Override
    protected int bindLayout() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {
        dataBinding.register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewModel.register(dataBinding.etName.getText().toString(),dataBinding.etPwd.getText().toString());
            }
        });
    }

    @Override
    protected void initData() {
        viewModel.success.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
                ARouter.getInstance().build("/app/MainActivity").navigation();
                finish();
            }
        });
        viewModel.fail.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
            }
        });
    }

    @Override
    protected Class<RegisterViewMolde> getViewModel() {
        return RegisterViewMolde.class;
    }
}